package com.sonic.simple.dao;

import com.alibaba.fastjson.JSONObject;
import com.sonic.simple.models.Devices;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

/**
 * @author ZhouYiXun
 * @des Devices数据库操作
 * @date 2021/8/16 20:29
 */
public interface DevicesRepository extends JpaRepository<Devices, Integer>, JpaSpecificationExecutor<Devices> {
    Devices findByAgentIdAndUdId(int agentId, String udId);

    List<Devices> findByAgentId(int agentId);

    List<Devices> findByIdIn(List<Integer> ids);

    List<Devices> findByPlatformOrderByIdDesc(int platform);

    @Query(value = "select avg(temperature) as avg from devices " +
            "where temperature <> 0 and status in (?1)", nativeQuery = true)
    Integer findTemper(List<String> ids);

    @Query(value = "select cpu from devices group by cpu", nativeQuery = true)
    List<String> findCpuList();

    @Query(value = "select size from devices group by size", nativeQuery = true)
    List<String> findSizeList();
}
